<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>班级信息-新增</title>
<link href="<%=path %>/css/style.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="<%=path %>/third/jquery-validation-1.14.0/lib/jquery.js"></script>
<script type="text/javascript" src="<%=path %>/js/common.js"></script>
<script type="text/javascript" src="<%=path %>/third/My97DatePicker/WdatePicker.js"></script> 

<script language="JavaScript" src="js/jquery.js"></script>
<script src="js/cloud.js" type="text/javascript"></script>
<script type="text/javascript" src="js/templatemo-script.js"></script>
<script type="text/javascript" src="<%= basePath%>js/bootstrap.min.js"></script>  

<style type="text/css">
.verification{
     color:#FF0000;
     fornt-size:20px;
}
.err{
     color:#FF0000;
     fornt-size:13px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){	
	  $("select").each(function(){	 	
         $(this).after("<font class='verification' id='f1'>&nbsp;&nbsp;*&nbsp;&nbsp;</font>");      
	 });
	  $("#classId").each(function(){	 	
         $(this).after("<font class='verification' id='f2'>&nbsp;&nbsp;*&nbsp;&nbsp;</font>");      
	 });
	  $("#className").each(function(){	 	
         $(this).after("<font class='verification' id='f3'>&nbsp;&nbsp;*&nbsp;&nbsp;</font>");      
	 });
	 
	  $("select").blur(function(){	 	 
		 $("#f1").remove(); 
		 $("#f11").remove(); 	 
			 if(this.value =="")
			 {
			    $(this).after("<font class='err' id = 'f11'>&nbsp;&nbsp;<img id = 'f1' width='23px' src='<%=path%>/images/err.png'/>新建班级对应专业不为空！</font>");
			 }
			 else{
			    $(this).after("&nbsp;&nbsp;<img id = 'f1' width='23px' src='<%=path%>/images/right.png'/>");
			 }	
	   });
	    $("#classId").blur(function(){	 	 
		 $("#f2").remove(); 
		 $("#f12").remove();	 
			 if(this.value =="")
			 {
			    $(this).after("<font class='err' id = 'f12'>&nbsp;&nbsp;<img id = 'f2' width='23px' src='<%=path%>/images/err.png'/>班级编号不能为空！</font>");
			 }
			 else{
			    $(this).after("&nbsp;&nbsp;<img id = 'f2' width='23px' src='<%=path%>/images/right.png'/>");
			 }	 	 
	   });
	   $("#className").blur(function(){	 	 
		  $("#f3").remove();
		 $("#f13").remove();	 
			 if(this.value =="")
			 {
			    $(this).after("<font class='err' id = 'f13'>&nbsp;&nbsp;<img id = 'f3' width='23px' src='<%=path%>/images/err.png'/>班级名称不能为空！</font>");
			 }
			 else{
			    $(this).after("&nbsp;&nbsp;<img id = 'f3' width='23px' src='<%=path%>/images/right.png'/>");
			 }	 	 
	   });
	   
	    $("#btn").click( function(){	 
		$("select").trigger("blur");
		$("#classId").trigger("blur");
		$("#className").trigger("blur");
		var flag = $("#f11").length+$("#f12").length+$("#f13").length;
		console.log($("#f11").length+","+$("#f12").length+","+$("#f13").length);
		if(flag==0){
		//console.log("-------");
		  $("#addClass").submit();
	     }
		 
		 });
 });
</script>

<script type="text/javascript">
$(function(){		

	$(function(){
		findAllAcademy('selectedAcademy');
	})
	/*******联动开始*********/  
	//$("#selectedAcademy").click(function(){
	   // alert("点击事件");
	//	findAllAcademy('selectedAcademy');
		// hideMultiOper();
//	});
	 //异步查找所有学院
	function findAllAcademy(domId){
		$.ajax({
			type:"POST",
			dataType:"JSON",
			url:"<%=basePath%>biz/DataJson_FindAllAcademy.action",
			data:{"query":""},
			success:function(data){
					//$("#"+domId+"").empty();
			       // data=JSON.parse(data);
			       // console.log("测试数组123"+data);
					//$("#"+domId+"").empty();
					//$("#"+domId+"").find("option").remove();
					if(null  != data && undefined  !=data){
						for(var i = 0; i < data.length; i++){
							$("#"+domId+"").append("<option value='"+data[i].academyId+"'>"+data[i].academyName+"</option>");
						}
						// $("#"+domId+"").change();	 
					}
			}
		});
	}
	//异步查找已选学院的专业
	function findAllMajor(academyId , seleMajor){
		//console.log("+++++++++++++++"+academyId)
		$.ajax({
			type:"POST",
			dataType:"JSON",
			url:"<%=basePath%>biz/DataJson_FindAllMajorByAcademy.action",
			data:{"query":JSON.stringify({"academyId":academyId})},
			success:function(data){
			//console.log(data)
		      //  let json = JSON.parse(data)
				$("#"+seleMajor+"").find("option").remove();
				//console.log("测试数组123456"+json);
				if(null  != data && undefined  != data){
					for(var i = 0; i < data.length; i++){
						//console.log("iiiiiiiiiiiiii"+i)
						$("#"+seleMajor+"").append("<option value='"+data[i].majorId+"'>"+data[i].majorName+"</option>");
					}
					$("#"+seleMajor+"").change();
				}
			}
		});
	}
	//异步查找已选专业的班级
	function findAllClass(majorId , seleClass){
	console.log("测试查找班级时的专业id----"+majorId);
		$.ajax({
			type:"POST",
			dataType:"JSON",
			url:"<%=basePath%>biz/DataJson_FindAllClassByMajor.action",
			data:{"query":JSON.stringify({"majorId":majorId})},
			success:function(data){
			     //   let json=JSON.parse(data)
					$("#"+seleClass+"").find("option").remove();
					if(null  != data && undefined  != data){
						for(var i = 0; i < data.length; i++){
							console.log("iiiiiiiiiiiiii"+i)
							$("#"+seleClass+"").append("<option value='"+data[i].classId+"'>"+data[i].className+"</option>");
						}									
						 $("#"+seleClass+"").change();
						
					}
			}
		});
	}
	//批量操作-已选学院改变事件
	 $("#selectedAcademy").change(function() {  
	    console.log($(this).val());
	    //console.log($(this).text());
	 	findAllMajor($(this).find("option:selected").val(),'selectedMajor');
	 	$("input[name='selectedCheckbox']:checked").each(function(){
	 		var seleAcademyId = $("#selectedAcademy option:selected").val();
	 		var seleAcademyName = $("#selectedAcademy option:selected").text();
	 		$(this).parent().nextAll().children("input[name^='academyId']").val(seleAcademyId);
	 		$(this).parent().nextAll().children("input[name^='academyName']").val(seleAcademyName);
	 		//将批量操作的学院下拉列表添加到当前行的下拉列表
	 		var dom = $(this).parent().nextAll().children("input[name^='academyId']").next();
	 		dom.find("option").remove();
	 		$("#selectedAcademy").find("option").each(function(){
	 			var newOption = "<option value="+$(this).val()+">"+$(this).text()+"</option>";
	 			dom.append(newOption);
	 		});
	 	});
	}); 
	//批量操作-已选专业改变事件
	 $("#selectedMajor").change(function() {  
	 	console.log("++++++++++++++++++++++"+$(this).find("option:selected").val())
	 	findAllClass($(this).find("option:selected").val(),  'selectedClass');
	 	$("input[name='selectedCheckbox']:checked").each(function(){
	 		var seleMajorId = $("#selectedMajor option:selected").val();
	 		var seleMajorName = $("#selectedMajor option:selected").text();
	 		$(this).parent().nextAll().children("input[name^='majorId']").val(seleCabinetCode);
	 		$(this).parent().nextAll().children("input[name^='majorName']").val(seleCabinetName);
	 		var dom = $(this).parent().nextAll().children("input[name^='majorId']").next();
	 		dom.find("option").remove();
	 		$("#selectedMajor").find("option").each(function(){
	 			var newOption = "<option value="+$(this).val()+">"+$(this).text()+"</option>";
	 			dom.append(newOption);
	 		});
	 	});
	}); 
	//批量操作-已选班级改变事件
	 $("#selectedClass").change(function() {
	 console.log("测试已选班级改变事件----"+$(this).find("option:selected").val());
	 	$("input[name='selectedCheckbox']:checked").each(function(){
	 		var seleClassId = $("#selectedClass option:selected").val();
	 		var seleClassName = $("#selectedClass option:selected").text();
	 		$(this).parent().nextAll().children("input[name^='classId']").val(seleClassId);
	 		$(this).parent().nextAll().children("input[name^='className']").val(seleClassName);
	 		//将批量操作的盒子下拉列表添加到当前行的下拉列表
	 		var dom = $(this).parent().nextAll().children("input[name^='classId']").next();
	 		dom.find("option").remove();
	 		$("#selectedClass").find("option").each(function(){
	 			var newOption = "<option value="+$(this).val()+">"+$(this).text()+"</option>";
	 			dom.append(newOption);
	 		});

	 	});
	});
}); 


</script>
</head>

<body>

	<div class="place">
		<span>位置：</span>
		<ul class="placeul">
		    <li><a href="#">首页</a></li>
			<li><a href="#">班级管理</a></li>
			<li><a href="#">新增班级</a></li>
		</ul>
	</div>

	<div class="formbody" id="tab1">

		<div class="formtitle">
			<span>班级信息</span>
		</div>

		<form action="<%=basePath%>/biz/ServiceClass_add.action" method="post"  enctype="multipart/form-data" id="addClass" class="addClass">
			<ul class="forminfo">
	 <li><label><front class="label">学院</front></label><select name="userCollege"id="selectedAcademy" class="scinput">								 
						<option value="">请选择学院 ...</option>					
						</select></li> 
    <li><label><front class="label">专业</front></label><select name="majorId"id="selectedMajor" class="scinput">										 
						<option value="">请选择专业...</option>					
						</select></li>
			<li><label>班级编号</label><input name="classId" id="classId" type="text"  class="dfinput" />
			<li><label>班级名称</label><input name="className" id="className" type="text"  class="dfinput" />
			</li>
				
			
			<br />
			<ul class="forminfo"> <li><label>&nbsp;</label><input name="" type="button" class="btn" value="确认保存" id="btn"/></li>
			</ul>
		</form>
	</div>

</body>



</html>
